package com.pingan.haofang.searchcloud.common.configuration;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author baojimin518
 * @version 1.0
 * @create 2018/11/15 17:56
 */
@Configuration
public class  IncBuildThreadPoolConfiguration {


    @Bean("incConsumerThreadCPool")
    public ThreadPoolExecutor incConsumerThreadCPool(@Value("${indexBuild.incBuildPoolSize:20}") Integer poolSzie) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(poolSzie, poolSzie, 30, TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(Integer.MAX_VALUE), new ThreadFactoryBuilder().setNameFormat(" inc-msg-pool-%d").build());
        executor.allowCoreThreadTimeOut(true);
        return executor;
    }

}
